<template>
  <ele-modal
    :width="950"
    :visible="visible"
    :confirm-loading="loading"
    :title="'审核通过'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <div class="padding-15" style="padding-left: 80px">
      <div class="bg-f5f5f5 padding-15">
        <div
          >退款会清空客户储值卡帐户余额，但不会删除额储值卡帐户，请谨慎操作！</div
        >
        <div
          >注意：清空客户储值卡帐户余额前，请确保客户已知晓，且已与客户协商解决帐户余额款项处置问题！</div
        >
      </div>
    </div>
    <a-form
      :label-col="{ md: { span: 5 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="24" :sm="24" :xs="24">
          <a-form-item label="会员昵称" :colon="false">
            <div>{{ info.nickname || '' }}</div>
          </a-form-item>
          <a-form-item label="会员姓名" :colon="false">
            <div>{{ info.name || '' }}</div>
          </a-form-item>
          <a-form-item label="会员手机" :colon="false">
            <div>{{ info.mobile || '' }}</div>
          </a-form-item>
          <a-form-item label="储值卡号" :colon="false">
            <div>{{ info.value_card_no?.value_card_no || '' }}</div>
          </a-form-item>
          <a-form-item label="储值卡金额" :colon="false">
            <div>{{ info.deposit || '' }}</div>
          </a-form-item>
          <a-form-item label="应退金额" :colon="false">
            <div>{{ info.amount || '' }}</div>
          </a-form-item>
          <a-form-item
            label="实退金额"
            :colon="false"
            v-bind="validateInfos.real_amount"
          >
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.real_amount"
            />
          </a-form-item>
          <a-form-item
            label="支付方式"
            :colon="false"
            v-bind="validateInfos.pay_type"
          >
            <a-select
              allow-clear
              placeholder="请选择"
              optionFilterProp="label"
              :options="payOptions"
              v-model:value="form.pay_type"
            />
          </a-form-item>
          <a-form-item label="支付时间" :colon="false">
            <a-date-picker
              class="ele-fluid"
              valueFormat="YYYY/MM/DD"
              placeholder="请选择"
              v-model:value="form.pay_time"
              autocomplete="off"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';

  import { get_pay_type_select } from '@/api/setting/pay_type';
  import { get_value_card_refund_detail } from '@/api/order/value_card_refund';
  // 表格列配置
  const useForm = Form.useForm;

  const emit = defineEmits(['done', 'update:visible']);

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    editData: Object
  });

  // 提交状态
  const loading = ref(false);
  const payOptions = ref([]);
  const info = ref({});

  // 表单数据
  const form = reactive({
    order_sn: props.editData.order_sn,
    status: 2,
    real_amount: '',
    pay_type: null,
    pay_time: '',
    reject_cause: ''
  });

  onMounted(() => {
    get_pay_type_select().then((res) => {
      payOptions.value = res;
    });
    if (props.editData.order_sn) {
      get_value_card_refund_detail({ order_sn: props.editData.order_sn }).then(
        (res) => {
          info.value = res;
        }
      );
    }
  });

  // 表单验证规则
  const rules = reactive({
    real_amount: [
      {
        required: true,
        message: '请输入实退金额',
        type: 'string',
        trigger: 'blur'
      }
    ],
    pay_type: [
      {
        required: true,
        message: '请选择支付方式',
        type: 'string',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);

  /* 保存*/
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
